package com.allwees.bs.c.common.auth.oauth.google;

import com.alibaba.fastjson.JSONObject;
import com.allwees.bs.c.common.auth.constant.EAuthType;
import com.allwees.bs.c.common.auth.util.HttpUtil;
import com.allwees.bs.c.module.user.req.ThirdPartLoginReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * google认证处理器
 *
 */
@Slf4j
@Component
@Lazy(false)
public class GoogleAuthHandler extends BaseGoogleAuthHandler {
	@Value("${google.resource.userInfoUri}")
	protected String googleBaseUrl;

	@Override
	public EAuthType getAuthType() {
		return EAuthType.GOOGLE;
	}

	@Override
	protected JSONObject fetchUserInfo(ThirdPartLoginReq req) {
		String url = String.format(googleBaseUrl, req.getToken());
		log.info(String.format("google auth params：%s", url));
		return HttpUtil.get(url);
	}
}
